<template>
  <div class="box">
    <div id="printTest">
      <div
        class="box_printTest"
        v-for="(item, index) in printList"
        :key="index"
        style="page-break-after: always"
      >
        <div class="header">
          <div class="header-icon-box">
            <img src="@/assets/common/company_logo.png" />
            <span class="title">广州众山精密科技有限公司</span>
          </div>
          <h2 class="header-title">生产领料单</h2>
          <div class="header-qrcode" ref="qrCodeUrl"></div>
        </div>
        <div class="container">
          <div class="container-basic-info">
            <div class="basic-info-row">
              <div class="row-item-modify">
                <span class="label">领料单号: </span>
                <span class="value">{{ item.billCode }}</span>
              </div>
              <div class="row-item-modify">
                <span class="label">工单单号: </span>
                <span class="value">{{ item.workOrderCode }}</span>
              </div>
            </div>
            <div class="basic-info-row">
              <div class="row-item-modify">
                <span class="label">领用车间: </span>
                <span class="value">{{ item.destProdOrgName }}</span>
              </div>
              <div class="row-item-modify">
                <div class="label">打印人:</div>
                <div class="value">{{ item.printBizBillUserName }}</div>
              </div>
            </div>
            <div class="basic-info-row">
              <div class="row-item-modify">
                <span class="label">打印日期: </span>
                <span class="value">{{ item.printBizBillTime }}</span>
              </div>
            </div>
          </div>
          <table id="printId">
            <thead>
              <tr>
                <td v-for="(hItem, hIdx) in tableHeader" :key="hIdx">
                  {{ hItem.label }}
                </td>
              </tr>
            </thead>
            <tbody v-if="item.bizDetailDetailList.length">
              <tr v-for="(sItem, sIdx) in item.bizDetailDetailList" :key="sIdx">
                <td>{{ (sIdx + 1) * 10 }}</td>
                <td>{{ sItem.materialCode }}</td>
                <td>{{ sItem.materialName }}</td>
                <td>{{ sItem.warehouseName }}</td>
                <td>
                  {{ sItem.num }}{{ sItem.numUnitCode }}({{
                    sItem.numUnitName
                  }})
                </td>
                <td>
                  {{ sItem.weight }}{{ sItem.weightUnitCode }} ({{
                    sItem.weightUnitName
                  }})
                </td>
                <td>{{ sItem.remark }}</td>
              </tr>
            </tbody>
          </table>
          <div class="container-order-info">
            <div class="order-info-row">
              <div class="row-item-modify">
                <span class="label">制单人: </span>
                <span class="value">{{ item.createUserName }}</span>
              </div>
              <div class="row-item-modify">
                <span class="label">物流: </span>
                <span class="value"></span>
              </div>
              <div class="row-item-modify">
                <span class="label">出库人: </span>
                <span class="value"></span>
              </div>
              <div class="row-item-modify">
                <span class="label">审核人: </span>
                <span class="value"></span>
              </div>
              <div class="row-item-modify">
                <span class="label">生产: </span>
                <span class="value"></span>
              </div>
            </div>
          </div>
          <!-- <div class="container-footer-info">表单编号：TRIO-2024-1011-1503</div> -->
        </div>
      </div>
    </div>
    <div></div>
  </div>
</template>

<script>
import printJS from "print-js";
import QRCode from "qrcodejs2";
export default {
  data: () => ({
    tableHeader: [
      { label: "行号" },
      { label: "原料料号" },
      { label: "物料名称" },
      { label: "仓库名称" },
      { label: "领用数量" },
      { label: "领用重量" },
      { label: "备注" },
    ],
  }),
  props: {
    printList: {
      type: Array,
      default: () => [],
    },
  },
  methods: {
    async printHandle() {
      let flag = await this.creatQrCode();
      if (flag) {
        printJS({
          printable: "printTest",
          type: "html",
          targetStyles: ["*"],
        });
      }
    },
    creatQrCode() {
      return new Promise((resolve) => {
        const qrcodeURL = this.$refs.qrCodeUrl;
        qrcodeURL.forEach((item, index) => {
          let qrcode = new QRCode(item, {
            text: this.printList[index].billCode, // 需要转换为二维码的内容
            width: 96,
            height: 96,
            colorDark: "#000",
            colorLight: "#ffffff",
            // correctLevel: QRCode.CorrectLevel.H,
          });
          console.log(qrcode);
          resolve(true);
        });
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  background: white;
}
.box_printTest {
  margin-left: 30px;
  width: 1000px;
  .header {
    display: flex;
    flex-shrink: 0;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 32px;
    border-bottom: 1px solid black;
    .header-icon-box {
      display: flex;
      .icon {
      }
      .title {
        line-height: 48px;
        font-size: 20px;
        font-weight: 500;
        color: #181b92;
      }
      img {
        display: inline-block;
        width: 48px;
        height: 48px;
      }
    }
    .header-title {
      flex: 1;
      text-align: center;
      // margin-left: -10px;
      font-weight: 600;
      font-size: 24px;
      transform: scale(2);
      width: 0;
    }
    .header-qrcode {
      display: block;
      width: 96px;
      height: 96px;
      // transform: scale(2);
    }
  }
  .container {
    width: 100%;
    .container-basic-info {
      padding: 28px 0;
      .basic-info-row {
        display: flex;
        justify-content: space-between;
        padding: 12px 0;
        .row-item-modify {
          flex: 1;
          flex-shrink: 0;
          font-size: 18px;
          display: flex;
          flex-wrap: nowrap;
          min-width: 1px;
          line-height: 24px;

          .label {
            display: block;
            min-width: 90px;
            text-align: end;
            padding-right: 14px;
          }
          .value {
            flex: 1;
            padding-right: 32px;
            // overflow: hidden;
          }
          .min-label {
            min-width: 46px;
          }
          .max-label {
            min-width: 90px;
          }
        }
        .row-item-textarea {
          flex: 1;
          font-size: 18px;
          display: flex;
          .max-label {
            min-width: 90px;
          }
        }
      }
    }

    table {
      border: 1px solid black;
      width: 100%;
      word-wrap: break-word;
      word-break: break-all;
      vertical-align: middle;
      thead {
        background: #f3f3f3;
        td {
          min-width: 90px;
          height: 56px;
        }
      }
      tbody {
        td {
          padding: 16px;
          border-right: 1px solid black;
        }
      }
      td {
        min-height: 56px;
        padding-left: 16px;
        text-align: left;
        border-right: 1px solid black;
        border-bottom: 1px solid black;
      }
    }
    .container-order-info {
      display: block;
      margin: 24px 0 0;
      min-height: 18px;
      .order-info-row {
        display: flex;
        .row-item-modify {
          flex: 1;
        }
      }
    }
    .container-footer-info {
      padding: 28px 0 0;
      font-weight: 500;
      font-size: 18px;
    }
  }
}

/* 去掉页眉页脚 */
@page {
  size: auto;
  margin: 0mm;
}
</style>
